package com.example.redisTask;

import org.junit.Before;
import org.junit.Test;
import redis.clients.jedis.Jedis;

import java.io.BufferedReader;
import java.io.FileReader;
import java.util.HashMap;
import java.util.List;

public class RedisAPI {
    Jedis jedis;

    @Before
    public void init(){
         jedis= new Jedis("master", 6379);
    }

    @Test
    public void get(){
        String s = jedis.get("k1");
        System.out.println(s);

    }

    @Test
    public void set(){
        String set = jedis.set("set", "test");
        System.out.println(set);
    }

    @Test
    public void lpush(){
        jedis.lpush("test","java","python");
    }

    @Test
    public void blpop(){
        List<String> test = jedis.blpop(20,"test");
        System.out.println(test);
    }

    @Test
    public void hashStudent()throws Exception{

        BufferedReader br = new BufferedReader(new FileReader("F:\\数加\\代码\\bigdatespring\\data\\students.txt"));
        String line;
        while ((line=br.readLine())!=null){

            String[] split = line.split(",");

            String id = split[0];
            String name = split[1];
            String age = split[2];
            String sex = split[3];
            String clazz = split[4];
            HashMap<String, String> map = new HashMap<>();
            map.put("id",id);
            map.put("name",name);
            map.put("age",age);
            map.put("sex",sex);
            map.put("clazz",clazz);

            jedis.hmset("teacher:"+id,map);


        }

        br.close();

    }

}
